package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFile;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {
    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    @AutoFile(OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void save(Dish dish);

    Page<DishVO> page(DishPageQueryDTO dishPageQueryDTO);

    Dish getById(Long id);

    void deleteById(List<Long> ids);

    @AutoFile(OperationType.UPDATE)
    @Options( useGeneratedKeys = true, keyProperty = "id")
    void update(Dish dish);


    List<Dish> list(Dish dish);

    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where setmeal_id=#{setmealId}")
    List<Dish> getBySetmealId(Long id);

    Integer countStatus(Integer status);
}
